package org.wmq.travelagency02.helper;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.Map;

public class JwtLoginHelper {
    private static final Logger logger = LoggerFactory.getLogger(JwtLoginHelper.class);
    private static final String secretKey = "wmq00000000000000000000000000000000000000000000000000000000000012345678901234567890"; // 确保密钥正确
    private static final long ttlMillis = 3600000*24; // 1小时过期时间

    public static String createJwtToken(String subject) {
        long nowMillis = System.currentTimeMillis();
        Date now = new Date(nowMillis);

        try {
            String result = Jwts.builder()
                    .setSubject(subject)
                    .setIssuedAt(now)
                    .setExpiration(new Date(nowMillis + ttlMillis))
                    .signWith(SignatureAlgorithm.HS256, secretKey) // 确保使用HS256算法
                    .compact();
            logger.info("产生jwt:{}",result);
            return result;
        } catch (Exception e) {
            logger.error("生成JWT时发生异常", e);
            throw new RuntimeException("生成JWT时发生异常", e);
        }
    }



}